﻿function OrtOpenCenterWindow(URL, Name, Features) {
    var nWidth;
    var nHeight;
    var nLeft;
    var nTop;
    var strVal;
    var nPos;
    var strComb;
    var i;
    var chVal;
    nLeft = 0;
    nTop = 0;
    if (Features == null)
        return (window.open(URL, Name, Features));
    strVal = Features.toUpperCase();
    if (strVal.indexOf("LEFT", 0) >= 0 || strVal.indexOf("TOP", 0) >= 0)
        return (window.open(URL, Name, Features));
    if ((nPos = strVal.indexOf("WIDTH", 0)) < 0)
        return (window.open(URL, Name, Features));
    if ((nPos = strVal.indexOf("=", nPos)) < 0)
        return (window.open(URL, Name, Features));
    strComb = "";
    for (i = nPos + 1; i < Features.length; i++) {
        chVal = Features.charAt(i);
        if (chVal == " " || (chVal >= "0" && chVal <= "9"))
            strComb += chVal;
        else
            break;
    }
    if ((nWidth = eval(TrimString(strComb))) <= 0)
        return (window.open(URL, Name, Features));
    if ((nPos = strVal.indexOf("HEIGHT", 0)) < 0)
        return (window.open(URL, Name, Features));
    if ((nPos = strVal.indexOf("=", nPos)) < 0)
        return (window.open(URL, Name, Features));
    strComb = "";
    for (i = nPos + 1; i < Features.length; i++) {
        chVal = Features.charAt(i);
        if (chVal == " " || (chVal >= "0" && chVal <= "9"))
            strComb += chVal;
        else
            break;
    }
    if ((nHeight = eval(TrimString(strComb))) <= 0)
        return (window.open(URL, Name, Features));
    nLeft = (window.screen.width - nWidth) / 2;
    nTop = (window.screen.height - nHeight) / 2;
    Features += ",left=" + nLeft + ",top=" + nTop;
    return (window.open(URL, Name, Features));
}


//nWidth = screen.availWidth - 10;
//nHeight = screen.availHeight - 30;

//OrtOpenCenterWindow(strURL, "","toolbar=no,location=no,directories=no,status=no," + "scrollbars=no,menubar=no,copyhistory=no,left=0,top=0,resizable=yes," + "width=" + nWidth + ",height=" + nHeight);
//setTimeout("close()",0);
var wShow = null;
var wShow2 = null;
function CloseOpened(wWindow) {
    if (wWindow != null) {
        try {
            if (!wWindow.closed)
                wWindow.close();
        }
        catch (e) {
        }
    }
}

function ShowLink(strCode, nWidth, nHeight) {
    //最多只能打开三层窗口

    if ((window.opnner == wShow) && (wShow != null)) {
        CloseOpened(wShow2);
        wShow2 = OrtOpenCenterWindow(strCode, "", "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,copyhistory=no,left=120,top=100,resizable=yes," + "width=" + nWidth + ",height=" + nHeight);
        wShow2.focus();
    }
    else {
        CloseOpened(wShow);
        wShow = OrtOpenCenterWindow(strCode, "", "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,copyhistory=no,left=125,top=90,resizable=yes," + "width=" + nWidth + ",height=" + nHeight);
    }

}

function js_openpage(url) {
    var newwin = window.open(url, "NewWin", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=60,top=70,width=780,height=580");
    newwin.focus();
    //return false;
}

function ShowDialog(url) {
    window.showModalDialog(url, "dialogWidth=600px;dialogHeight=480px");
}




function getkeyCode(evt)
{
    evt = evt ? evt : (window.event ? window.event : null); 
    if (evt.charCode){
        return String.fromCharCode(evt.charCode);
    }else{
        return String.fromCharCode(evt.keyCode);
    }
}
function getStrInput(obj,inputStr)
{
    var docSel = document.selection.createRange();
    oSel = docSel.duplicate();
    oSel.text = '';
    var srcRange = obj.createTextRange();
    oSel.setEndPoint('StartToStart', srcRange);
    return oSel.text + inputStr + srcRange.text.substr(oSel.text.length);
}
function validateKey(obj,isUseTime,inputStr)
{
  var str="";
  try
  {
    str = getStrInput(obj,inputStr);
  }catch (e){
    str = trim(obj.value+inputStr);
  }
if (isUseTime){return /^[ \:\-\d]*$/.test(str);}
else{return /^[\-\d]*$/.test(str);}
}



function validateDate(obj,isUseTime)
{
var str = trim(obj.value);
if (str == ''){return true;}
var isOk = false;
if (isUseTime)
{
isOk = /^((((1[6-9]|[2-9]\d)\d{2})[-](0?[13578]|1[02])[-](0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})[-](0?[13456789]|1[012])[-](0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})[-]0?2[-](0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29)) d{1,2}:d{1,2}:?d{0,1,2}$/.test(str);
}
else
{
isOk = /^((((1[6-9]|[2-9]\d)\d{2})[-](0?[13578]|1[02])[-](0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})[-](0?[13456789]|1[012])[-](0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})[-]0?2[-](0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29))$/.test(str);
}
if (isOk){return true;}
else{alert('请输入正确的日期值，如：2008-08-08');
obj.select();
return false;}
}

function setFocus(obj)
{
        if (obj)
        {
            try
            {
                obj.select();
			    obj.focus();
            }
            catch(e) {}
        }
}



function showWait(isshow)
{
    var obj=document.getElementById('divshowwait');
    if (obj)
    {
        if (isshow)
        {
            obj.style.display='block';
        }
        else
        {
            obj.style.display='none';
        }
    }
    return true;
}


//将回车键改为tab键//

//document.onkeydown = function (event) 
//{ 
//  try{
//    var evt = null;
//    if (arguments.length==1){
//        evt=arguments[0];
//    }else{
//        evt = (window.event ? window.event : null);
//    }	
//    if (evt.charCode){
//        if (evt.charCode==13) 
//        {
//    	    var el=evt.srcElement || evt.target;
//            if (el){
//	            evt.charCode=9;
//	        }
//        }
//    }else{
//        if (evt.keyCode==13) 
//        {
//    	    var el=evt.srcElement || evt.target;
//            if (el){
//	            evt.keyCode=9;
//	        }
//        }
//    }
//  }catch(e){}
//}

//取消右键//

//document.oncontextmenu = function () {
//    var evt = null;
//    if (arguments.length==1){
//        evt=arguments[0];
//    }else{
//        evt = (window.event ? window.event : null);
//    }
//    if (evt){	
//        evt.returnValue=false;
//    }
//} 

